﻿using System.Collections.Generic;

namespace NDK.Module.StationLogic
{
    public class Carrier
    {
        public List<CarrierModel> carrierList = new List<CarrierModel>();
        public CarrierModel CarrierA;
        public CarrierModel CarrierB;

        public static Carrier Instance = new Carrier();
        private Carrier()
        { }

        public void Init()
        {
            carrierList.Clear();
            CarrierA = new CarrierModel
            {
                Name = CarrierName.A.ToString(),
                Status = CarrierStatus.FREE,
                Location = CarrierLocation.Load,
            };
            CarrierB = new CarrierModel
            {
                Name = CarrierName.B.ToString(),
                Status = CarrierStatus.FREE,
                Location = CarrierLocation.Load,
            };
            carrierList.Add(CarrierA);
            carrierList.Add(CarrierB);
        }

        public CarrierModel GetCarrier()
        {
            if (Instance.CarrierA.Status == CarrierStatus.FREE && Instance.CarrierB.Status == CarrierStatus.FREE)
            {
                if (Model.Common.屏蔽治具1 || Model.Common.屏蔽治具2)
                {
                    if (Model.Common.屏蔽治具1 && !Model.Common.屏蔽治具2)
                        return Instance.CarrierA;
                    else if (!Model.Common.屏蔽治具1 && Model.Common.屏蔽治具2)
                        return Instance.CarrierB;
                    else
                        return null;
                }
                else
                {
                    if (Instance.CarrierA.SelectCount == 0)
                    {
                        return Instance.CarrierA;
                    }
                    else
                    {
                        return Instance.CarrierB;
                    }
                }
                
            }
            else if (Instance.CarrierA.Status == CarrierStatus.FREE && Instance.CarrierB.Status == CarrierStatus.BUSY)
            {
                return Instance.CarrierA;
            }
            else if (Instance.CarrierA.Status == CarrierStatus.BUSY && Instance.CarrierB.Status == CarrierStatus.FREE)
            {
                return Instance.CarrierB;
            }
            else
            {
                return null;
            }
        }
    }

    public class CarrierModel
    {
        public string Name { get; set; }
        public CarrierStatus Status { get; set; }
        public string Action { get; set; }
        public CarrierLocation Location { get; set; }
        public int SelectCount { get; set; } = 0;

    }

    public enum CarrierName
    {
        A, B
    }

    public enum CarrierStatus
    {
        FREE, BUSY
    }

    public enum CarrierLocation
    {
       Load,Measure,Unload
    }
}
